﻿using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;

namespace BattleNet.D3.Performance
{
    class Program
    {
        static void Main(string[] args)
        {
            /// Set Caching Mode
            D3ServiceClient.CacheSetting = System.ServiceModel.CacheSetting.AlwaysOn;

            Collection<long> elapsedMillisecondsCollection = new Collection<long>();

            /// Create D3 Service Client
            using (D3ServiceClient serviceClient = new D3ServiceClient(Regions.EU, Localizations.de_DE))
            {
                /// Profile
                Stopwatch stopwatch = new Stopwatch();
                for (int i = 0; i < 100; i++)
                {
                    stopwatch.Start();

                    Profile profile = serviceClient.GetProfile("Asesjix", 2766);

                    stopwatch.Stop();
                    elapsedMillisecondsCollection.Add(stopwatch.ElapsedMilliseconds);
                    stopwatch.Reset();
                }

                Console.WriteLine("Profile Avarage: {0} milliseconds", elapsedMillisecondsCollection.Average());
                elapsedMillisecondsCollection.Clear();

                /// Hero
                for (int i = 0; i < 100; i++)
                {
                    stopwatch.Start();

                    Hero hero = serviceClient.GetHero("Asesjix", 2766, 1655714);

                    stopwatch.Stop();
                    elapsedMillisecondsCollection.Add(stopwatch.ElapsedMilliseconds);
                    stopwatch.Reset();
                }

                Console.WriteLine("Hero Avarage: {0} milliseconds", elapsedMillisecondsCollection.Average());
                elapsedMillisecondsCollection.Clear();

                /// Item Information
                for (int i = 0; i < 100; i++)
                {
                    stopwatch.Start();

                    ItemInformation itemInformation = serviceClient.GetItemInformation("item/CjkIwPWAzgQSBwgEFUd7JfwdhBydJx1NT9lkHcIayXsd1WaKlB1HCWKcHbJX1e4wCTi1AUAAUBJgpAIY8ZLUPVACWAA");

                    stopwatch.Stop();
                    elapsedMillisecondsCollection.Add(stopwatch.ElapsedMilliseconds);
                    stopwatch.Reset();
                }

                Console.WriteLine("Item Information Avarage: {0} milliseconds", elapsedMillisecondsCollection.Average());
                elapsedMillisecondsCollection.Clear();

                /// Follower Information
                for (int i = 0; i < 100; i++)
                {
                    stopwatch.Start();

                    FollowerInformation followerInformation = serviceClient.GetFollowerInformation(FollowerTypes.enchantress);

                    stopwatch.Stop();
                    elapsedMillisecondsCollection.Add(stopwatch.ElapsedMilliseconds);
                    stopwatch.Reset();
                }

                Console.WriteLine("Follower Information Avarage: {0} milliseconds", elapsedMillisecondsCollection.Average());
                elapsedMillisecondsCollection.Clear();

                /// Artisan Information
                for (int i = 0; i < 100; i++)
                {
                    stopwatch.Start();

                    ArtisanInformation artisanInformation = serviceClient.GetArtisanInformation(ArtisanTypes.blacksmith);

                    stopwatch.Stop();
                    elapsedMillisecondsCollection.Add(stopwatch.ElapsedMilliseconds);
                    stopwatch.Reset();
                }

                Console.WriteLine("Artisan Information Avarage: {0} milliseconds", elapsedMillisecondsCollection.Average());
                elapsedMillisecondsCollection.Clear();

                Console.Read();
            }
        }
    }
}
